package edu.bit.water.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.bit.water.dao.EntityEvaEntPrdInfoDao;
import edu.bit.water.entity.EntityEvaEntPrdInfo;

/**
 * 用于处理生产实际情况的业务层
 * @author HJS
 *
 */
@Service
public class EntityEvaEntPrdInfoService {
	
	@Autowired
	private EntityEvaEntPrdInfoDao entityEvaEntPrdInfoDao;
	
	/**
	 * 
	 * @param entityEvaEntPrdInfo 生产实际情况实体
	 * @return 成功返回1,失败返回0
	 */
	public int insert(EntityEvaEntPrdInfo entityEvaEntPrdInfo) {
		//计算单位产品取水量
		double unitProductWaterWd = entityEvaEntPrdInfo.getWaterWithdrawal()/entityEvaEntPrdInfo.getActualYield();
		entityEvaEntPrdInfo.setUnitProductWaterWd(unitProductWaterWd);
		return entityEvaEntPrdInfoDao.insert(entityEvaEntPrdInfo);
	}
	/**
	 * 
	 * @param id 要删除记录的主键
	 * @return 成功返回1,失败返回0
	 */
	public int deleteId(List<Integer> ids) {
		try {
			for (Integer id : ids) {
				entityEvaEntPrdInfoDao.deleteId(id);
			}
			return 1;
		} catch (Exception e) {
			// TODO: handle exception
			return 0;
		}
	}
	/**
	 * 
	 * @param fd 要删除记录的外键
	 * @return 成功返回1,失败返回0
	 */
	public int deleteFd(int fd) {
		return entityEvaEntPrdInfoDao.deleteFd(fd);
	}
	/**
	 * 更新生产情况实体
	 * @param entityEvaEntPrdInfo 生产情况实体
	 * @return 成功返回1,失败返回0
	 */
	public int update(EntityEvaEntPrdInfo entityEvaEntPrdInfo) {
		double unitProductWaterWd = entityEvaEntPrdInfo.getWaterWithdrawal()/entityEvaEntPrdInfo.getActualYield();
		entityEvaEntPrdInfo.setUnitProductWaterWd(unitProductWaterWd);
		return entityEvaEntPrdInfoDao.update(entityEvaEntPrdInfo);
	}
	/**
	 * 查询生产情况实体
	 * @param id 外键
	 * @return 成功返回记录,没有返回null
	 */
	public List<EntityEvaEntPrdInfo> select(int id){
		return entityEvaEntPrdInfoDao.select(id);
	}
}
